package br.edu.unibratec.Projeto.util;

import br.edu.unibratec.Projeto.R;
import br.edu.unibratec.Projeto.controller.Evento;
import br.edu.unibratec.Projeto.view.MapActivity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.text.format.DateFormat;
import android.util.Log;

public class AgendadorReceiver extends BroadcastReceiver{

	@Override
	public void onReceive(Context contexto, Intent intent) {

		if (intent.getSerializableExtra("evento") != null) {
			Evento evento = (Evento) intent.getSerializableExtra("evento");

			Notification notificacao = new Notification(R.drawable.icon, "Evento marcado!", evento.getData().getTime());
			NotificationManager nManager = (NotificationManager) contexto.getSystemService(Context.NOTIFICATION_SERVICE);
			PendingIntent pit = PendingIntent.getActivity(contexto, 0, new Intent(contexto, MapActivity.class), 0);
			notificacao.flags |= Notification.FLAG_AUTO_CANCEL;
			String data = (String) DateFormat.format("dd/MM/yyyy kk:mm", evento.getData());
			notificacao.setLatestEventInfo(contexto, "Hora do evento: " + evento.getDescricao(), "Marcada pras " + data, pit);
			nManager.notify((int) evento.getId_Evento(), notificacao);
			
		}
	}

}
